<%@page import="com.lyf.util.DateUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
	<title>CRM-contact-show</title>
	<meta charset="UTF-8">
	<%@ include file="../include/head.jsp" %>
</head>

<body class="crm">
	
<jsp:include page="../include/top.jsp">
	<jsp:param value="contact" name="tag"/>
</jsp:include>


<div class="container-fluid">
	<div class="row-fluid">
		<div class="row-fluid">
		<div class="span8">
		<div class="well screen">
		<c:if test="${param.from == null }">
			<div class="page-header header"> 导入联系人 </div>
			<div id="parties_loading" class="live_search_spinner" behavior="spinner">
				<div class="liner">
				<h3>处理中</h3>
					<img alt="WorkXP" src="${basePath }/img/indicator.gif">
				</div>
			</div>
			<div id="main" class="main">
				<p class="intro"> 您可以从以下几种方式，快速的把您已有的联系人导入到CRM。 </p>
				<div class="import_option">
					<h1>
						<a href="${basePath }/contact/import?from=csv">上传CSV文件</a>
					</h1>
					<p>大部分数据库和表格程序都可以导出CSV格式的文件</p>
				</div>
				<div class="import_option">
					<h1>
						<a href="${basePath }/contact/import?from=xls">上传Excel文件</a>
					</h1>
					<p>目前我们只支持微软老版本的Excel格式，还不支持.xlsx格式，请在导入前转成.xls格式</p>
				</div>
				<p class="submit">
					<a class="btn" href="${basePath }/contact/list">取消导入</a>
				</p>
			</div>
		</c:if>
		<c:if test="${param.from == 'csv' }">
			<div class="page-header header"> 上传CSV文件 </div>
			<div id="parties_loading" class="live_search_spinner" behavior="spinner">
				<div class="liner">
					<h3>处理中</h3>
					<img alt="WorkXP" src="${basePath }/img/indicator.gif">
				</div>
			</div>
			<div id="main" class="main">
				<form id="import_form" class="simple_form new_contact_import" novalidate="novalidate" method="post" enctype="multipart/form-data" action="${basePath }/contact/upload" accept-charset="UTF-8">
					<input id="contact_import_src" type="hidden" value="csv" name="from">
					<div class="control-group string optional">
						<label class="string optional control-label" for="contact_import_user">请选择你要导入的CSV格式的文件，请保存时选择UTF-8编码（将编辑好的xls文件用记事本打开，另存为时选择文件编码为UTF-8）</label>
						<div class="controls">
							<input id="file" type="file" size="30" required="required" name="file">
						</div>
					</div>
					
					<div class="form-actions">
						<input class="btn btn-primary" type="submit" value="上传导入" name="commit" data-loading-text="处理中..">
						<a class="btn" href="${basePath }/contact/list">取消</a>
					</div>
					
				</form>
			</div>
			
		</c:if>
		
		<c:if test="${param.from == 'xls' }">
			<div class="page-header header"> 上传Excel文件 </div>
			<div id="parties_loading" class="live_search_spinner" behavior="spinner">
				<div class="liner">
					<h3>处理中</h3>
					<img alt="WorkXP" src="${basePath }/img/indicator.gif">
				</div>
			</div>
			<div id="main" class="main">
				<form id="import_form" class="simple_form new_contact_import" novalidate="novalidate" method="post" enctype="multipart/form-data" action="${basePath }/contact/upload" accept-charset="UTF-8">
					<input id="contact_import_src" type="hidden" value="xls" name="from">
					<div class="control-group string optional">
						<label class="string optional control-label" for="contact_import_user">请选择你要导入的Excel文件(.xls)，请保存时选择UTF-8编码（将编辑好的xls文件用记事本打开，另存为时选择文件编码为UTF-8）</label>
						<div class="controls">
							<input id="file" type="file" size="30" required="required" name="file">
						</div>
					</div>
					<div class="controls">
					</div>
					<div class="form-actions">
						<input class="btn btn-primary" type="submit" value="上传导入" name="commit" data-loading-text="处理中..">
						<a class="btn" href="${basePath }/contact/list">取消</a>
					</div>
				</form>
				
			</div>
		</c:if>
		</div>
		</div>
		<script type="text/javascript">
			function validateFail(msg) {
			alert(msg);
			$("#file").val('');
			$("#import_form :submit").button('reset');
				return false;
			}
			$(document).ready(function() {
				$("#import_form").submit(function() {
					var fileName = $("#file").val();
					if (fileName.length < 1) {
						return validateFail("请选择要导入的文件!");
					}
					var extension = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
					var src = $("#contact_import_src").val();
					if(src == 'csv' || src == 'outlook') {
						if(extension != 'csv') {
							return validateFail("请上传CSV格式的文件!");
						}
					} else if(src == 'xls') {
						if(extension != 'xls') {
							return validateFail("导入时格式不正确，目前我们只支持微软老版本的Excel格式，还不支持.xlsx格式，请在导入前转成.xls格式");
						}
					}
				});
			});
		</script>
		
		<div class="span4 sidebar"> </div>
	</div>
</div>
	

</div>

</body></html>
